package com.platform.mobile.operator;

import java.util.LinkedHashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.platform.base.SysException;
import com.platform.bean.PageInfo;
import com.platform.mobile.bean.GetFollowedRequest;
import com.platform.mobile.bean.GetFollowedResponse;
import com.platform.mobile.bean.LoginAssitantInfo;
import com.platform.mobile.bean.ReqBean;
import com.platform.mobile.bean.ResBean;
import com.platform.mobile.bean.ResultBean;
import com.platform.mobile.factory.Operator;
import com.platform.mobile.service.PaitentService;
import com.platform.mobile.session.SessionManager;

/**
 * 获取回访列表
 * @author inven
 *
 */
@Component
public class GetFollowed extends Operator{
	
	private static Logger log = LoggerFactory.getLogger(GetFollowed.class);
	
	@Autowired
	private PaitentService service;

	@SuppressWarnings("unchecked")
	@Override
	public ResBean operate(ReqBean reqBean) throws SysException {
		
		log.info("进入到GetFollowed业务处理类，处理[" + reqBean.getClientInfo() + "]用户请求");
		ResBean resBean = new ResBean();
		resBean.setClientInfo(reqBean.getClientInfo());
		resBean.setJsonrpc("2.0");
		resBean.setMethod("GetFollowed");
		ResultBean result = new ResultBean();
		
		GetFollowedRequest request = new GetFollowedRequest();
		GetFollowedResponse response = new GetFollowedResponse();
		
		try{
			
			Object params = reqBean.getParams();
			if(params != null){
				
				LinkedHashMap<String, Object> paramMap 
					= (LinkedHashMap<String, Object>)params;
				request.setIsFollowed((int)paramMap.get("isFollowed"));
				LinkedHashMap<String, Object> pageInfoMap
					= (LinkedHashMap<String, Object>)paramMap.get("pageInfo");
				PageInfo pageInfo = new PageInfo();
				pageInfo.setCurrPage((Integer)pageInfoMap.get("currPage"));
				pageInfo.setPageSize((Integer)pageInfoMap.get("pageSize"));
				request.setPageInfo(pageInfo);
				
				Object session 
					= SessionManager.getInstance()
						.getSessionInfo(reqBean.getSessionID());
				Integer aidId 
					= Integer.parseInt(((LoginAssitantInfo)session).getId());
				
				response = service.getFollowedView(request, aidId);
				
				result.setResultStatus("1");
				result.setInfo("获取回访记录列表成功");
				result.setData(response);
				
			}
			
		}catch(Exception e){
			e.printStackTrace();
			result.setResultStatus("0");
			result.setInfo("服务器异常");
			result.setData(null);
		}
		
		resBean.setResult(result);
		return resBean;
	}

}
